{template 'web/common/common'}
{template 'web/land/navbar'}
<link rel="stylesheet" type="text/css" href="../addons/kundian_farm/resource/css/style.css" />
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.css" />
<div class="panel panel-success">
    <div class="panel-heading">
        <h3 class="panel-title">
            种植详情
        </h3>
    </div>
    <div class="panel-body">
        <div class="ibox-content">
            <form action="{url 'site/entry/send',array('m'=>'kundian_farm','version_id'=>$_GPC['version_id'])}" id="searchform" method="post">
                <div class="row" style="padding: 0 15px;">
                    <!--<div class="col-sm-3">-->
                        <!--<input type="text" class="form-control" placeholder="土地" name="title" value="{$title}">-->
                    <!--</div>-->
                    <div class="col-sm-2">
                        <!--<button type="submit" class="btn btn-default " style="margin-right:5px;">查询</button>-->
                        <!--<a class="btn btn-primary" href="{url 'site/entry/send',array('m'=>'kundian_farm','op'=>'edit','version_id'=>$_GPC['version_id'])}">增加</a>-->
                    </div>
                </div>
            </form>
        </div>
        <form action="" method="post" class="form-horizontal form">
            <input type="hidden" name="token" value="{$_W['token']}">

            <div class="table-responsive panel-body">
                <table class="table-striped table-bordered table-hover dataTables-example table">
                    <thead class="navbar-inner">
                    <tr>
                        <th>ID</th>
                        <th>种植名称</th>
                        <th>封面</th>
                        <th>面积（单位：㎡）</th>
                        <th>是否种植</th>
                        <th>种植天数</th>
                        <th>编辑预计成熟时间</th>
                        <th style="text-align:right;">操作</th>
                    </tr>
                    </thead>
                    <tbody id="level-list">
                    {loop $list $index $item}
                    <tr>
                        <td><div class="type-parent">{$item['id']}</div></td>
                        <td><div class="type-parent">{$item['send_name']}</div></td>
                        <td><div class="type-parent"><img src="{$item['cover']}" alt="种子封面" style="width: 70px;height: 70px;"></div></td>
                        <td><div class="type-parent">{$item['count']} ㎡</div></td>
                        <td><div class="type-parent" style="width: 52px;height: 32px;">
                            {if $item['status']==1}
                            已种植
                            {elseif $item['status']==2}
                            已成熟
                            {else}
                            未种植
                            {/if}
                        </div></td>
                        <td><div class="type-parent">{$item['day']}</div></td>
                        <td><div class="type-parent">
                            <input type="date" class="expect_time" data-id="{$item['id']}" name="expect_time" value="{$item['expect_time']}">

                            <!--<button class="btn btn-primary saveTime" data-id="{$item['id']}">保存</button>-->
                        </div></td>
                        <td style="text-align:right;">
                            {if $item['status']==0}
                            <!--<a class="btn btn-default btn-xs sowSeed" data-id="{$item['id']}"><i class="fa fa-edit"></i>已播种</a>-->
                            {elseif $item['status']==1}
                            <!--<a class="btn btn-warning btn-xs seedGroup" data-id="{$item['id']}"><i class="fa fa-edit"></i>已成熟</a>-->
                            {elseif $item['status']==2}
                            <!--<a class="btn btn-success btn-xs seedPick" data-id="{$item['id']}"><i class="fa fa-edit"></i>摘取</a>-->
                            {else}
                            <!--已摘取-->
                            {/if}

                            <select name="seed_status" class="seed_status" data-id="{$item['id']}" style="width: 200px;">
                                <option value="0" <?php if($item['status']==0){echo 'selected';}?> >待种植</option>
                                <option value="1" <?php if($item['status']==1){echo 'selected';}?> >已播种</option>
                                <option value="2" <?php if($item['status']==2){echo 'selected';}?> >已成熟</option>
                                <option value="3" <?php if($item['status']==3){echo 'selected';}?> >摘取</option>
                            </select>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
                <div style="text-align: right;">
                    {$pager}
                </div>
            </div>
        </form>


    </div>
</div>
<script>
    require(["../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.js"],function(){
        $(function(){

            $(".seed_status").change(function () {
                var id=$(this).attr("data-id");
                var status=$(this).val();
                var that=$(this);
                var id=$(this).attr('data-id');
                swal({
                    title: '提示',
                    text: "确认修改状态吗？",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '确认',
                    cancelButtonText: '取消',
                }).then(function(isConfirm) {
                    if(isConfirm) {
                        $.ajax({
                            type: "post",
                            url: "{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'changeSeedStatus','version_id'=>$_GPC['version_id'])}",
                            data: {id: id, status: status},
                            dataType: 'json',
                            success: function (res) {
                                if (res.status == 1) {
                                    swal('操作成功!', '操作成功!', 'success');
                                } else {
                                    swal('操作失败!', '操作失败!', 'error');
                                }
                            }
                        })
                    }
                })
            })
            //删除
            $(".delete").click(function(){
                var that=$(this);
                var id=$(this).attr('data-id');
                swal({
                    title: '确定删除吗?',
                    text: "确定删除吗?",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '删除',
                    cancelButtonText: '取消',
                }).then(function(isConfirm) {
                    if (isConfirm) {
                        $.ajax({
                            type:"post",
                            url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'delete','version_id'=>$_GPC['version_id'])}",
                            data:{id:id},
                            dataType:'json',
                            success:function(res){
                                if(res.status==1){
                                    swal('操作成功!', '操作成功!', 'success');
                                    that.parent().parent().remove();
                                }else{
                                    swal('操作失败!', '操作失败!', 'error');
                                }
                            }
                        })
                    }
                })
            });
            $(".expect_time").change(function () {
                var id=$(this).attr('data-id');
                var expect_time=$(this).val();
                $.ajax({
                    type:"post",
                    url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'expect_time','version_id'=>$_GPC['version_id'])}",
                    data:{id:id,expect_time:expect_time},
                    dataType:'json',
                    success:function(res){
                        if(res.status==1){
                            swal('操作成功!', '操作成功!', 'success');
                            that.parent().parent().remove();
                        }else{
                            swal('操作失败!', '操作失败!', 'error');
                        }
                    }
                })
            })
        })
    })
</script>